home *** CD-ROM | disk | FTP | other *** search
- DEFINT A-Z
- DECLARE SUB ClearBuf ()
- DECLARE SUB PrintString (Txt$, Row, Col, Colr)
- DECLARE FUNCTION Editor (In$, StrPtr, Row, Col, Colr)
- DECLARE FUNCTION WaitKey ()
- '$INCLUDE: 'd:\misc\scancode.inc'
-
- CLS
- In$ = STRING$(20, 32)
- PRINT "["; In$; "]";
- LSET In$ = "This is a test."
- DO
- Result = Editor(In$, StrPtr, 1, 2, 15)
- LOOP UNTIL (Result = 13) OR (Result = 27)
- In$ = RTRIM$(In$)
- END
-
- SUB ClearBuf
-
- DEF SEG = 0
- Temp& = PEEK(&H41A) + (PEEK(&H41B) * 256&)
- Head = Temp& AND &HFFFF& 'Clear keyboard buffer
- POKE &H41C, Head AND 255 'by setting head ptr
- POKE &H41D, Head \ 256 'equal to tail ptr.
-
- END SUB
-
- FUNCTION Editor (In$, StrPtr, Row, Col, Colr)
-
- STATIC CsrSize 'STATIC variables preserved
- STATIC InsFlag 'between CALLs.
-
- IF CsrSize = 0 THEN
- DEF SEG = 0 'Determine bottom scan line
- IF PEEK(&H463) = &HB4 THEN 'for cursor, depending on
- CsrSize = 12 'display type.
- ELSE
- CsrSize = 7
- END IF
- END IF
-
- Length = LEN(In$) 'Save length of In$
- IF StrPtr = 0 THEN StrPtr = 1 'Start editing at first char
- CALL PrintString(In$, Row, Col, Colr)
-
- IF InsFlag THEN
- LOCATE , , 1, 0, CsrSize 'Block cursor
- ELSE
- LOCATE , , 1, CsrSize - 1, CsrSize 'Underscore
- END IF
-
- DO
- LOCATE Row, Col + StrPtr - 1
- K = WaitKey 'Get a keystroke
- SELECT CASE K
- CASE Enter, Esc
- EXIT DO
- CASE 8 'Backspace
- IF StrPtr > 1 THEN
- StrPtr = StrPtr - 1
- LSET In$ = LEFT$(In$, StrPtr - 1) + MID$(In$, StrPtr + 1)
- END IF
- CASE Home
- StrPtr = 1
- CASE Left
- IF StrPtr > 1 THEN
- StrPtr = StrPtr - 1
- END IF
- CASE Right
- IF StrPtr < Length THEN
- StrPtr = StrPtr + 1
- END IF
- CASE EndKey
- FOR I = Length TO 1 STEP -1
- Char = ASC(MID$(In$, I, 1))
- IF (Char <> 32) THEN
- IF Char THEN
- EXIT FOR
- END IF
- END IF
- NEXT
- IF I THEN StrPtr = I + 1
- CASE Ins
- InsFlag = InsFlag XOR -1
- IF InsFlag THEN
- LOCATE , , 1, 0, CsrSize
- ELSE
- LOCATE , , 1, CsrSize - 1, CsrSize
- END IF
- CASE Del
- LSET In$ = LEFT$(In$, StrPtr - 1) + MID$(In$, StrPtr + 1)
- CASE IS > 31
- K$ = CHR$(K)
- IF StrPtr <= Length THEN
- IF InsFlag THEN
- LSET In$ = LEFT$(In$, StrPtr - 1) + K$ + MID$(In$, StrPtr, Length - StrPtr)
- StrPtr = StrPtr + 1
- ELSE
- MID$(In$, StrPtr, 1) = K$
- StrPtr = StrPtr + 1
- END IF
- END IF
- CASE ELSE
- EXIT DO
- END SELECT
- CALL PrintString(In$, Row, Col, Colr)
- LOOP
- Editor = K 'Function returns scan code
- LOCATE , , 0 'of last key pressed.
-
- END FUNCTION
-
- SUB PrintString (A$, Row, Col, Colr)
-
- BG = (Colr AND 112) \ 16
- FG = (Colr AND 128) \ 8 + (Colr AND 15)
- COLOR FG, BG 'Set new color...
- LOCATE Row, Col 'and location...
- PRINT A$; 'and print!
-
- END SUB
-
- FUNCTION WaitKey
-
- CALL ClearBuf 'Clear kybd buffer.
- DO
- A$ = INKEY$ 'Wait for a keypress.
- LOOP UNTIL LEN(A$)
- IF LEN(A$) = 2 THEN 'If an extended key...
- WaitKey = -ASC(MID$(A$, 2, 1)) 'Return negative code.
- ELSE
- WaitKey = ASC(A$) 'Else, return keycode.
- END IF
-
- END FUNCTION
-
-